package com.billdowney.qq.robot.timedTask;

import com.billdowney.qq.robot.bean.Dayz.Dayzurl;
import com.billdowney.qq.robot.bean.Dayz.Jisharizhi;
import com.billdowney.qq.robot.bean.QQjiqiren.Qunxinxi;
import com.billdowney.qq.robot.dayzUtil.jisharizhijiexi;
import com.billdowney.qq.robot.mapper.Dayz.JisharizhiMapper;
import com.billdowney.qq.robot.service.Dayz.IDayzuserService;
import com.billdowney.qq.robot.service.QQjiqiren.IDayzurlService;
import com.billdowney.qq.robot.service.QQjiqiren.IQunxinxiService;
import com.billdowney.qq.robot.service.QQjiqiren.IShijianzhilingService;
import com.billdowney.qq.robot.util.IpUtil;
import com.billdowney.qq.robot.util.ShiJianUtil;
import net.mamoe.mirai.Bot;
import net.mamoe.mirai.contact.Group;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
@EnableScheduling
public class Dingshi {
    @Autowired
    private IDayzuserService dayzuserService;
    @Autowired
    private IQunxinxiService qunxinxiService;

    @Autowired
    private IDayzurlService dayzurlService;
    @Autowired
    private IShijianzhilingService shijianzhilingService;

    @Autowired
    private JisharizhiMapper jisharizhiMapper;


//    @Scheduled()
//    @Scheduled(cron = "*/5 * * * * ?")
    /**
     *
     * 用户在银行中的金额每天的利息
     *
     * */
//    @Scheduled(cron = "0 0 3 * * ?")//每天凌晨3点执行一次：0 0 3 * * ?
//// @Scheduled(cron = "0/5 * * * * ?")//每天凌晨3点执行一次：0 0 3 * * ?
////只新增运行中的qq机器人
//    public void ss() throws SocketException {
//        Qunxinxi s= new Qunxinxi();
//        s.setIp(IpUtil.getLocalIp4Address().get().toString().replaceAll("/",""));
//        List<Qunxinxi> list=qunxinxiService.selectQunxinxiList(s);
//             for (int l = 0 ;l< list.size();l++) {
////                 System.out.println();
//                 if (list.get(l).getShouyi() != 0) {
//                     Dayzuser user = new Dayzuser();
//                     user.setUserqqqun(list.get(l).getQunqq());
//
//                     List<Dayzuser> dayzuserList = dayzuserService.dingshiselectDayzuserList(user);
//                     if (dayzuserList.size() != 0) {
//                         for (int k = 0; k < dayzuserList.size(); k++) {
////
//                             double jiner = Double.parseDouble(dayzuserList.get(k).getJiner());//金额利息
//                             double jinbi = dayzuserList.get(k).getJinbi();//金币利息
//                             int ssss = (int) (jiner / 100 * list.get(l).getShouyi());
//                             int ss = Integer.parseInt(dayzuserList.get(k).getLixi());
//                             int jis = ss + ssss;
//                             dayzuserList.get(k).setLixi(jis + "");
//                             double ssss1 =  (jinbi / 100 * list.get(l).getShouyi());
//                             double jis1 = jinbi + ssss1;
//                             dayzuserList.get(k).setJinbi(jis1);
////                          System.out.println(dayzuserList.get(k).toString());
//                             dayzuserService.updateDayzuser(dayzuserList.get(k));
//                         }
//                     }
//                 }
//
//             }
//    }
//
//    /**
//     *
//     * 用户金额超过1亿 转化金币 1亿=10金币   1金币 = 1000万
//     *
//     * */
//    @Scheduled(cron = "0 0 4 * * ?")//每天4点执行一次：0 0 4 * * ?
////    @Scheduled(cron = "0/5 * * * * ?")//每天凌晨3点执行一次：0 0 3 * * ?
//    public void ss1(){
//        List<Dayzuser> dayzuserList = dayzuserService.dingshiselect100000000();//查询金额大于1亿的玩家
//        if (dayzuserList.size()==0){
//            return;
//        }
//       int yiyi =100000000;
//        for (Dayzuser dayzuser :dayzuserList){
//            int jiner = Integer.parseInt(dayzuser.getJiner());//金额利息
//            int s =jiner/yiyi;
//            int k= jiner-(s*yiyi);
//            dayzuser.setJiner(k+"");//剩余的金额
//            dayzuser.setJinbi(Double.valueOf(s*10));//转化的金币
//            dayzuserService.updateDayzuser(dayzuser);
//        }
//    }
//    /**
//     *定时发送事件信息
//     * */
////    @Scheduled(cron = "0/5 * * * * ?")//每分钟执行一次：0 0/1 * * * ?
//    @Scheduled(cron = "0 0/1 * * * ?")//每分钟执行一次：0 0/1 * * * ?
//    public void dingshifasong() throws UnsupportedEncodingException {
//        String ss =  ShiJianUtil.shijianshifen(new Date());
//        String shifen =  ShiJianUtil.shifen(new Date());
//        Shijianzhiling shijianzhiling  = new Shijianzhiling();
//        shijianzhiling.setChufa("定时任务"+ss);
//        List<Shijianzhiling> list =shijianzhilingService.selectdingshirenwuList(shijianzhiling);
//        shijianzhiling.setChufa("定时任务"+shifen);
//        list.addAll(shijianzhilingService.selectdingshirenwuList(shijianzhiling));
//        for (Shijianzhiling shijianzhiling1 :list){
//                shijianzhiling.setChufa(shijianzhiling1.getXiangying());
//                List<Shijianzhiling> plmm = shijianzhilingService.selectdingshirenwuList(shijianzhiling);
//            if (plmm.size()>0){
//                int index=(int)(Math.random()*plmm.size());
//                shijianzhiling1.setXiangying(plmm.get(index).getChufa()+","+plmm.get(index).getXiangying());
//            }
//            if (shijianzhiling1.getQqqun().equals(shijianzhiling1.getJiluqq())){
//                qqjiqirenController.huidiao(shijianzhiling1.getJilvjiqirenqq(),shijianzhiling1.getQqqun(),shijianzhiling1.getJiluqq(),shijianzhiling1.getXiangying());//个人返回
//            }else {
//              qqjiqirenController.huidiao(shijianzhiling1.getJilvjiqirenqq(),shijianzhiling1.getQqqun(),null,shijianzhiling1.getXiangying());//群返回
//            }
//        }
//    }
//
//    /**
//     *循环发送事件信息
//     * */
//    @Scheduled(cron = "0 0/1 * * * ?")//每分钟执行一次：0 0/1 * * * ?
//    public void xunhuanrenwu() throws UnsupportedEncodingException {
//        String ss =  ShiJianUtil.shijianshifen(new Date());
//        String shifen =  ShiJianUtil.shifen(new Date());
//        Shijianzhiling shijianzhiling  = new Shijianzhiling();
//        shijianzhiling.setChufa("循环任务"+ss);
//        List<Shijianzhiling> list =shijianzhilingService.selectdingshirenwuList(shijianzhiling);
//        shijianzhiling.setChufa("循环任务"+shifen);
//        list.addAll(shijianzhilingService.selectdingshirenwuList(shijianzhiling));
//
//
//        for (Shijianzhiling shijianzhiling1 :list){
//            shijianzhiling.setChufa(shijianzhiling1.getXiangying());
//            List<Shijianzhiling> plmm = shijianzhilingService.selectdingshirenwuList(shijianzhiling);
//            if (plmm.size()>0){
//                int index=(int)(Math.random()*plmm.size());
//                shijianzhiling1.setXiangying(plmm.get(index).getChufa()+","+plmm.get(index).getXiangying());
//            }
//            if (shijianzhiling1.getQqqun().equals(shijianzhiling1.getJiluqq())){
//                qqjiqirenController.huidiao(shijianzhiling1.getJilvjiqirenqq(),shijianzhiling1.getQqqun(),shijianzhiling1.getJiluqq(),shijianzhiling1.getXiangying());//个人返回
//            }else {
//                qqjiqirenController.huidiao(shijianzhiling1.getJilvjiqirenqq(),shijianzhiling1.getQqqun(),null,shijianzhiling1.getXiangying());//群返回
//            }
//        }
//    }

        @Scheduled(cron = "0 0/1 * * * ?")//每分钟执行一次：0 0/1 * * * ?
         public void 击杀通知() throws Exception{
            System.out.println("击杀执行"+ ShiJianUtil.shijianshifenmiao(new Date()));
            Qunxinxi qunxinxi= new Qunxinxi();
            qunxinxi.setIp(IpUtil.getLocalIp4Address().get().toString().replaceAll("/",""));
            List<Qunxinxi> qunxinxis = qunxinxiService.selectQunxinxiList(qunxinxi);

             if (qunxinxis.size()==0){
                return;
            }
            if (qunxinxis.get(0).getJiqirenqq()==null){
                return;
            }
             Dayzurl dayzurl=new Dayzurl();
             dayzurl.setQunqq(qunxinxis.get(0).getQunqq());
             dayzurl.setName("击杀文件url");
             List<Dayzurl> dayzurls = dayzurlService.selectDayzurlList(dayzurl);
                if (dayzurls.size()==0){return;}

            String 击杀消息;
            Bot b= Bot.getInstance(Long.parseLong(qunxinxis.get(0).getJiqirenqq())); //qq机器人
            Group group = b.getGroup(Long.parseLong(qunxinxis.get(0).getQunqq()));//目标群
            String fileName2 = dayzurls.get(0).getUrl();
            List<Jisharizhi> list = jisharizhijiexi.jiexijisharizhi(fileName2);
            if (list.size()==0)return;
            击杀消息 ="实时击杀通知：";
            for (int i=0 ;list.size()>i;i++ ) {

                Jisharizhi jiexijisharizhi = list.get(i);
                if (jiexijisharizhi==null){return;}
                jiexijisharizhi.setIp(IpUtil.getLocalIp4Address().get().toString().replaceAll("/",""));//给ip
                jiexijisharizhi.setQqqunhao(qunxinxis.get(0).getQunqq());
                jisharizhiMapper.insertJisharizhi(jiexijisharizhi);
            击杀消息+="\n击杀时间:\t"+jiexijisharizhi.getJishashijian()+
                    "\n击杀人员:\t"+jiexijisharizhi.getGongjizhe()+
//                    "\n攻击坐标:\t"+jiexijisharizhi.getGongjizuobiao()+
                    "\n使用武器:\t"+jiexijisharizhi.getWuqi()+
                    "\n被杀人员:\t"+jiexijisharizhi.getBeisharenyuan()+
                    "\n被杀坐标:\t"+jiexijisharizhi.getBeishazuobiao()+
                    "\n击杀距离:\t"+jiexijisharizhi.getJuli()+"m"+
                    "\n-----------------------------------------";
        }




            System.out.println(击杀消息);
            group.sendMessage(击杀消息);
        }



}
